package com.xumx.demo.controller;

import com.xumx.demo.customize.annotate.log.MethodLog;
import org.springframework.web.bind.annotation.*;

/**
 * 日志使用示例控制器
 */
@RestController
@RequestMapping("/logDemoController")
public class LogDemoController {

    /**
     * 示例接口1：默认日志配置
     */
    @MethodLog(description = "用户登录接口")
    @RequestMapping("/login")
    public LoginResponse login(@RequestParam String username,
                               @RequestParam String password) {
        // 模拟登录逻辑
        LoginResponse response = new LoginResponse();
        if ("admin".equals(username) && "123456".equals(password)) {
            response.setSuccess(true);
            response.setMessage("登录成功");
            response.setUserId("10001");
        } else {
            response.setSuccess(false);
            response.setMessage("用户名或密码错误");
        }
        return response;
    }

    /**
     * 示例接口2：自定义日志配置，忽略密码参数
     */
    @MethodLog(description = "用户注册接口",
            ignoreParamIndexes = {1},  // 忽略第二个参数（密码）
            expireDays = 90)
    @PostMapping("/register")
    public RegisterResponse register(@RequestParam String username,
                                     @RequestParam String password,
                                     @RequestParam String email) {
        // 模拟注册逻辑
        RegisterResponse response = new RegisterResponse();
        response.setSuccess(true);
        response.setMessage("注册成功");
        response.setUserId("10002");
        return response;
    }

    /**
     * 示例接口3：不记录出参
     */
    @MethodLog(description = "获取敏感信息接口",
            logOutput = false)  // 不记录出参
    @GetMapping("/sensitive/{userId}")
    public SensitiveInfo getSensitiveInfo(@PathVariable String userId) {
        // 模拟获取敏感信息
        SensitiveInfo info = new SensitiveInfo();
        info.setUserId(userId);
        info.setBankCard("6222 **** **** 1234");
        info.setIdCard("310********1234");
        return info;
    }

    // 响应类定义
    public static class LoginResponse {
        private boolean success;
        private String message;
        private String userId;

        // getter和setter省略
        public boolean isSuccess() {
            return success;
        }

        public void setSuccess(boolean success) {
            this.success = success;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public String getUserId() {
            return userId;
        }

        public void setUserId(String userId) {
            this.userId = userId;
        }
    }

    public static class RegisterResponse {
        private boolean success;
        private String message;
        private String userId;

        // getter和setter省略
        public boolean isSuccess() {
            return success;
        }

        public void setSuccess(boolean success) {
            this.success = success;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public String getUserId() {
            return userId;
        }

        public void setUserId(String userId) {
            this.userId = userId;
        }
    }

    public static class SensitiveInfo {
        private String userId;
        private String bankCard;
        private String idCard;

        // getter和setter省略
        public String getUserId() {
            return userId;
        }

        public void setUserId(String userId) {
            this.userId = userId;
        }

        public String getBankCard() {
            return bankCard;
        }

        public void setBankCard(String bankCard) {
            this.bankCard = bankCard;
        }

        public String getIdCard() {
            return idCard;
        }

        public void setIdCard(String idCard) {
            this.idCard = idCard;
        }
    }
}
